package 尊享面试.矩阵;

public class a531孤独像素 {
    static class Solution {
        public int findLonelyPixel(char[][] picture) {
            int ans = 0;
            for (int i = 0; i < picture.length; i++) {
                for (int j = 0; j < picture[i].length; j++) {
                    if (picture[i][j] == 'B' && check(picture, i, j)) {
                        ans++;
                    }
                }
            }
            return ans;
        }

        private boolean check(char[][] picture, int i, int j) {
            for (int k = 0; k < picture[0].length; k++) {
                if (k == j) continue;
                if (picture[i][k] == 'B') {
                    return false;
                }
            }
            for (int k = 0; k < picture.length; k++) {
                if (k == i) continue;
                if (picture[k][j] == 'B') {
                    return false;
                }
            }
            return true;
        }
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        char[][] picture = {{'W', 'W', 'B'}, {'W', 'B', 'W'}, {'B', 'W', 'W'}};
        System.out.println(solution.findLonelyPixel(picture));
    }
}
